<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        .box {
            width: 100px;
            height: 40px;
            border-radius: 30px;
            border: 1px solid #000;
            margin: auto;
            position: relative;
        }

        .box label {
            width: 40px;
            height: 40px;
            background-color: #ddd;
            position: absolute;
            border-radius: 30px;
            transition: .1s;
            left: 0;
        }

        input:checked+label {
            left: 60px;
            background-color: #f00;
        }
    </style>
</head>

<body>
    <div class="box">
        <input type="checkbox" id="a" hidden>
        <label for="a"></label>
    </div>


</body>

</html>